home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / cuj0696.zip / DWYER.ZIP / GAP.TST / PLANGAP.C < prev    next >
C/C++ Source or Header  |  1995-12-20  |  4KB  |  179 lines

  1. /* ============ */
  2. /* plangap.c    */
  3. /* ============ */
  4. #include <defcodes.h>
  5. #include <mconf.h>
  6. #include <miscdefs.h>
  7. #include <gapdefs.h>
  8. #include <gapprobs.c>
  9.  
  10. /* ==================================================== */
  11. /* PlanCupn - Prints Sample Sizes Required for Gap Test    */
  12. /* ==================================================== */
  13. #define    MAX_GAPS    100
  14. void
  15. main()
  16. {
  17.     AbortGracefully();            /* Make ^C Reasonable */
  18.  
  19.     while (main)
  20.     {
  21.     char    *LeftLbl;
  22.     int    k, m;
  23.     int    CellExpect, MaxGapCt, MinGapCt, WhereMax, WhereMin;
  24.     double  SumCellExpect;
  25.     double    HiLimit, LoLimit, GapProbs[MAX_GAPS+1], TotalProb;
  26.  
  27.     for (;;)
  28.     {
  29.         GetDbl("Enter Lower Limit of Gap [>=0,<1]: ",
  30.         &LoLimit);
  31.         if (LoLimit >= 0 && LoLimit < 1)
  32.         {
  33.         break;
  34.         }
  35.         fprintf(stderr, "Incorrect Entry\n");
  36.     }
  37.  
  38.     for (;;)
  39.     {
  40.         char    Prompt[64];
  41.         sprintf(Prompt, "Enter Upper Limit of Gap [> %g,<=1]: ",
  42.         LoLimit);
  43.  
  44.         GetDbl(Prompt, &HiLimit);
  45.  
  46.         if (HiLimit > LoLimit && HiLimit <= 1)
  47.         {
  48.         break;
  49.         }
  50.         fprintf(stderr, "Incorrect Entry\n");
  51.     }
  52.     MinGapCt = -1; MaxGapCt = -1; WhereMin = -1; WhereMax = -1;
  53.  
  54.     for (k = 0; k < MAX_GAP_LEN; ++k)
  55.     {
  56.         CalcGapProbs(k+1, LoLimit, HiLimit, GapProbs);
  57.  
  58.         {
  59.         double    MaxPerGap = -1;
  60.         for (m = k; m >= 0; --m)
  61.  
  62.         {
  63.             MaxPerGap =
  64.             __max(MaxPerGap, MIN_CELL_XPCT/GapProbs[m]);
  65.         }
  66.         if (MaxPerGap > (double)MAX_NUM_GAPS)
  67.         {
  68.             break;
  69.         }
  70.         else
  71.         {
  72.             MinGapCt = __max((int)MaxPerGap, MinGapCt);
  73.             if (MinGapCt == (int)MaxPerGap)
  74.             {
  75.             WhereMin = k;
  76.             }
  77.         }
  78.         MaxPerGap = -1;
  79.         for (m = k; m >= 0; --m)
  80.         {
  81.             MaxPerGap =
  82.             __max(MaxPerGap, MAX_CELL_XPCT/GapProbs[m]);
  83.         }
  84.         if (MaxPerGap > (double)MAX_NUM_GAPS)
  85.         {
  86.             break;
  87.         }
  88.         if (MaxPerGap > (double)MAX_NUM_GAPS)
  89.         {
  90.             break;
  91.         }
  92.         else
  93.         {
  94.             MaxGapCt = __max((int)MaxPerGap, MaxGapCt);
  95.             if (MaxGapCt == (int)MaxPerGap)
  96.             {
  97.             WhereMax = k;
  98.             }
  99.         }
  100.         }
  101.     }
  102.     printf("Gap Boundaries: (%g, %g)\n", LoLimit, HiLimit);
  103.     printf("K = %d, MAX_GAP_LEN = %d\n", k, MAX_GAP_LEN);
  104.     printf("MinGapCt = %d (@ k=%d), MaxGapCt = %d (@ k=%d)\n",
  105.         MinGapCt, WhereMin, MaxGapCt, WhereMax);
  106.     SumCellExpect = TotalProb = 0;
  107.     CalcGapProbs(WhereMax+1, LoLimit, HiLimit, GapProbs);
  108.     printf("\nProbabilities for Maximum Cell Expectation (%d)\n",
  109.         MAX_CELL_XPCT);
  110.     printf("Gap Len    Probability           Cell Expectation\n");
  111.  
  112.     for (m = 0; m <= WhereMax; ++m)
  113.     {
  114.         double  CellExpect = MaxGapCt * GapProbs[m];
  115.         printf("%4d%23.11e%14.f\n",
  116.         m, GapProbs[m], CellExpect);
  117.         TotalProb += GapProbs[m];
  118.         SumCellExpect += CellExpect;
  119.     }
  120.     printf("Totals:%20.11e%14.f\n", TotalProb, SumCellExpect);
  121.  
  122.     SumCellExpect = TotalProb = 0;
  123.     CalcGapProbs(WhereMin+1, LoLimit, HiLimit, GapProbs);
  124.     printf("\nProbabilities for Minimum Cell Expectation (%d)\n",
  125.         MIN_CELL_XPCT);
  126.     printf("Gap Len    Probability           Cell Expectation\n");
  127.     for (m = 0; m <= WhereMin; ++m)
  128.     {
  129.         double  CellExpect = MinGapCt * GapProbs[m];
  130.         printf("%4d%23.11e%14.f\n",
  131.         m, GapProbs[m], CellExpect);
  132.         TotalProb += GapProbs[m];
  133.         SumCellExpect += CellExpect;
  134.     }
  135.     printf("Totals:%20.11e%14.f\n", TotalProb, SumCellExpect);
  136. exit(1);
  137.     for (;;)
  138.     {
  139.         GetInt("Enter Maximum Gap Length [> 0]: ",
  140.         &MaxGapCt);
  141.         if (MaxGapCt > 0)
  142.         {
  143.         break;
  144.         }
  145.         fprintf(stderr, "Incorrect Entry\n");
  146.     }
  147.  
  148.     CalcGapProbs(MaxGapCt+1, LoLimit, HiLimit, GapProbs);
  149.  
  150.     for (;;)
  151.     {
  152.               GetInt("Enter Minimum Expectation For Each Gap:\t",
  153.         &CellExpect);
  154.  
  155.         if (CellExpect >= 1)
  156.         {
  157.         break;
  158.         }
  159.         fprintf(stderr, "Incorrect Entry\n");
  160.     }
  161.  
  162.     TotalProb = 0;
  163.     LeftLbl = ">= ";
  164.  
  165.     printf("Gap Len  Gap Probability     Cell Expectation"
  166.            "   # Variates Required\n");
  167.     for (k = MaxGapCt; k >= 0; --k)
  168.     {
  169.         double  DevReqd = ceil(0.5 + CellExpect/GapProbs[k]);
  170.         printf("%3s%3d  %.11e%10s", LeftLbl, k, GapProbs[k], "");
  171.         printf("%5d%15s%5.f\n", CellExpect, "", DevReqd);
  172.         TotalProb += GapProbs[k];
  173.         LeftLbl = "";
  174.     }
  175.  
  176.     printf("%26.11e  (Total)\n", TotalProb);
  177.     }
  178. }
  179.